package com.z.service.impl;

import com.z.dao.OrderDao;
import com.z.dao.impl.OrderDaoImpl;
import com.z.pojo.Cart;
import com.z.pojo.Order;
import com.z.service.OrderService;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OrderServiceImpl implements OrderService {
    private OrderDao orderDAO = new OrderDaoImpl();

    @Override
    public Integer addOrder(Order order) throws SQLException {

        return orderDAO.addOrder(order);
    }

    @Override
    public Map<Order, List<Cart>> findOrderByOid(String oid) throws SQLException {
        Map<Order, List<Cart>> map = new HashMap<>();
        map.put(orderDAO.findOrderByOid(oid), orderDAO.findOrderItemByOid(oid));
        return map;
    }

    @Override
    public Map<Order, List<Cart>> findOrderByUid(String uid) throws SQLException {
        Map<Order, List<Cart>> map = new HashMap<>();
        List<Order> orders = orderDAO.findOrderByUid(uid);
        for (Order order : orders) {

            map.put(order, orderDAO.findOrderItemByOid(order.getOid()));
        }

        return map;
    }
    @Override
    public Integer updateOrderByOid(String oid, Integer aid) throws SQLException {
        return orderDAO.updateOrderByOid(oid, aid);
    }
}
